package com.ciwong.epaper.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.application.EpaperConstant;
import com.ciwong.epaper.modules.epaper.util.EpaperJumpManager;
import com.ciwong.epaper.modules.me.util.MeJumpManager;

/**
 * Created by Administrator on 2017/7/31.
 */
public class RecordPermissionsDialog extends Dialog implements View.OnClickListener {


    private Context mContext;
    private TextView tx_dialog_content;
    private TextView tx_single_btn;

    public RecordPermissionsDialog(Context context) {
        super(context, R.style.dialog_network_tips);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_record_permissions);
        tx_dialog_content = (TextView) findViewById(R.id.tx_dialog_content);
        tx_single_btn = (TextView) findViewById(R.id.tx_single_btn);
        tx_dialog_content.setOnClickListener(this);
        tx_single_btn.setOnClickListener(this);
        String contentStr = tx_dialog_content.getText().toString();
        ForegroundColorSpan greenSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.light_blue));

        SpannableStringBuilder builder = new SpannableStringBuilder(contentStr);
        builder.setSpan(greenSpan, contentStr.length() - 6, contentStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tx_dialog_content.setText(builder);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tx_single_btn) {
            Activity activity = (Activity) mContext;
            EpaperJumpManager.jumpSystemToSetting(R.string.go_back, activity);
            dismiss();
        } else if (id == R.id.tx_dialog_content) {
            String url = EpaperConstant.H5_HOST + "FAQ/?brandId=" + EApplication.BRAND_ID;
            MeJumpManager.jumpToBrowser((Activity) mContext,
                    R.string.go_back, url,
                    mContext.getResources().getString(R.string.faq));
            dismiss();
        }
    }
}
